<?php

require_once("main.php");

require_once(DIR_LIB."VsCore".DIR_SEP."vsauth.php");
$auth = VsAuth::Instance();
if($auth->level() != 9) {
	echo "Unauthorized Access !!!";
	exit();
}

require_once(DIR_LIB."VsCore".DIR_SEP."db.php");

$db = VsDatabase::Instance();

/*
$q = "SELECT `id` FROM `operators`";

$oRes = $db->query($q);
while($or=mysql_fetch_object($oRes)) {

	$q = "SELECT `id` FROM `operations`";
	$opRes = $db->query($q);
	while($op = mysql_fetch_object($opRes)) {

		$q = "SELECT * FROM `operators_work`";
	}
}
*/


//=========================================================================================================================================


/* 
$tmp = array();
$arr = array();
$q = "SELECT * FROM `operators_work` ORDER BY operators_id, operations_id, date";
$res = $db->query($q);
while($o=mysql_fetch_assoc($res)) {
	if((!empty($tmp)) && ($tmp['operators_id']==$o['operators_id']) && ($tmp['operations_id']==$o['operations_id']) && ($tmp['date']==$o['date']))
		continue;

	array_push($arr, $o);
	$tmp = $o;
}

$q = "TRUNCATE TABLE `operators_work`";
$db->query($q);

$q = "INSERT INTO `operators_work` VALUES";
foreach($arr as $a) {
	$q .= "('".$a['operators_id']."', '".$a['operations_id']."', '".$a['date']."', '".$a['count']."', '".$a['price']."'),";
}

$q = rtrim($q, ',');
$db->query($q);

echo $q;
echo "<br />";
echo mysql_error();
*/



//===========================================================================================================================================


/* Repair Operations Names for Model 1097 */
$q = "SELECT * FROM `operations` WHERE `model_id`=23";
$res = $db->query($q);
while($r=mysql_fetch_object($res)) {
	$q = "UPDATE `operations` SET `operation_name`='".$r->operation_name."' WHERE `model_id`=22 AND `operation_id`='".$r->operation_id."'";
	echo $q."<br />"; 
	
	$db->query($q);
}


?>
